package io.dshubs.archives.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.dshubs.archives.entity.ArchiveBaseInfo;
import io.dshubs.archives.entity.ArchiveBaseRule;
import io.dshubs.archives.entity.ArchiveSpecialFiles;
import io.dshubs.archives.service.ArchiveSpecialFilesService;
import io.dshubs.commons.log.annotation.LogOperation;
import io.dshubs.commons.tools.constant.Constant;
import io.dshubs.commons.tools.page.PageData;
import io.dshubs.commons.tools.utils.Result;
import io.dshubs.commons.tools.validator.ValidatorUtils;
import io.dshubs.commons.tools.validator.group.AddGroup;
import io.dshubs.commons.tools.validator.group.DefaultGroup;
import io.dshubs.commons.tools.validator.group.UpdateGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 专题档案表 前端控制器
 * </p>
 *
 * @author tan
 * @since 2021-09-03
 */
@Api(tags = "档案专题")
@RestController
@RequestMapping("/special-files")
public class ArchiveSpecialFilesController {

    @Autowired
    private ArchiveSpecialFilesService archiveSpecialFilesService;
    
    @GetMapping("page")
    @ApiOperation("档案专题:page")
    @LogOperation("档案专题:page")
    public Result<PageData<ArchiveSpecialFiles>> page(@ApiIgnore @RequestParam Map<String, Object> params){
        return new Result<PageData<ArchiveSpecialFiles>>().ok(archiveSpecialFilesService.page(params));
    }


    @PostMapping
    @ApiOperation("保存")
    @LogOperation("档案专题:save")
    public Result save(@RequestBody ArchiveSpecialFiles archiveSpecialFiles){
        //效验数据
        ValidatorUtils.validateEntity(archiveSpecialFiles, AddGroup.class, DefaultGroup.class);

        archiveSpecialFilesService.insert(archiveSpecialFiles);
        return new Result();
    }

    @PutMapping
    @ApiOperation("修改")
    @LogOperation("档案专题:update")
    public Result update(@RequestBody ArchiveSpecialFiles archiveSpecialFiles){
        archiveSpecialFilesService.updateById(archiveSpecialFiles);
        return new Result();
    }

    @DeleteMapping()
    @ApiOperation("删除")
    @LogOperation("档案专题:delete")
    public Result delete(@RequestBody @NotNull(message = "批量删除id不能为空") List<Long> ids){
        archiveSpecialFilesService.deleteBatchIds(ids);
        return new Result();
    }

}
